﻿using Sustainalytics.Entities;
using System;

namespace Sustainalytics.Governance.BusinessLogic.Model
{
    public class GovernanceAlertDto
    {
        public static GovernanceAlertDto FromGovernanceAlert(GovernanceAlert gAlert, string host)
        {
            if (host.Contains("+"))
                host = host.Replace("+", "localhost");


            if (!host.EndsWith("/"))
                host += "/";
            var hostUri = new Uri(host);

            var result = new GovernanceAlertDto()
            {
                Id = gAlert.Id,
                CreatedDate = gAlert.CreatedDate,
                CreatedBy = gAlert.CreatedBy,
                PublicationDate = gAlert.PublicationDate,
                Title = gAlert.Title
            };

            if (gAlert.FileId != Guid.Empty)
            {
                result.FileId = gAlert.FileId;
                result.FileUrl = (new Uri(hostUri, hostUri.LocalPath + "api/v1/files/" + gAlert.FileId)).ToString().ToLowerInvariant();
            }

            return result;
        }

        public Guid Id { get; set; }
        public DateTime CreatedDate { get; set; }
        public string CreatedBy { get; set; }
        public DateTime PublicationDate { get; set; }
        public string Title { get; set; }
        public Guid FileId { get; set; } // alert pdf file id
        public string FileUrl { get; set; }
        public string FileName { get; set; }

    }
}
